<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue测试.html</title>
    <!--导入js package-->
    <script type="text/javascript" src="../01-vue_js/vue.js"></script>
</head>
<body>
<div id="root">
    遍历数组
    <br>
    <button @click.once="add">添加一个老刘</button>
    <ul>
        <li v-for="(p,index) of persons" :key="p.id">姓名：{{p.name}} -- 年龄：{{p.age}} <input type="text"></li>
    </ul>
</div>

<script type="text/javascript">
    // 关闭开发环境的警告提示
    Vue.config.productionTip = false
    // 创建vue的对象
    new Vue({
        el: '#root',
        data: {
            persons: [
                {id: '001', name: 'zhangsan', age: '20'},
                {id: '002', name: 'lisi', age: '18'},
                {id: '003', name: 'wangwu', age: '22'},
            ],
        },
        methods:{
            add(){
                const p={id:"004",name:"laoliu",age:'34'}
                this.persons.unshift(p)
            }
        }
    })
</script>
</body>
</html>